import { Component, Inject, OnInit } from "@angular/core";
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from "@angular/material";

export interface IYes {
  show: boolean;
}

export interface INo {
  show: boolean;
}

export interface DialogData {
  yes: IYes;
  no: INo;
  msg: string;
  type: string;
}
@Component({
  selector: "app-dialog",
  templateUrl: "./dialog.component.html",
  styleUrls: ["./dialog.component.scss"]
})
export class DialogComponent implements OnInit {
  agree = true;
  constructor(
    public dialogRef: MatDialogRef<DialogComponent>,
    @Inject(MAT_DIALOG_DATA) public data: DialogData
  ) {
    this.data = {
      ...{
        yes: {
          show: true
        },
        no: {
          show: true
        },
        msg: "",
        type: ""
      },
      ...this.data
    };
  }

  onYes(): void {
    this.dialogRef.close(true);
  }

  onNo(): void {
    this.dialogRef.close(false);
  }

  onAgree() {
    if (this.agree) {
      this.dialogRef.close(true);
    }
  }

  ngOnInit() {}
}
